package com.tianmu.connector.client.runner;

import com.tianmu.connector.server.BinlogConnectorException;
import com.tianmu.connector.server.BinlogConnectorStarter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 数据库监听启动器
 * @author tianmu
 */
@Slf4j
@Component
public class BinLogApplicationRunner implements ApplicationRunner {

    @Resource
    private BinlogConnectorStarter binlogConnectorStarter;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        new Thread(this::start).start();
    }

    void start() {
        try {
            binlogConnectorStarter.start();
        } catch (BinlogConnectorException e) {
            log.error(e.getMessage(), e);
        }
    }
}
